package com.ojoin.ojoin.eb_spider.service;

import com.ojoin.ojoin.eb_spider.utils.Response;
import org.springframework.stereotype.Service;

/**
 * Created by liaowuhen on 2017/1/13.
 */

@Service
public interface UploadPersonGroupService {


    Response upload(String Message, String token, String type) ;

    /*public File fromByteToFile(byte[] buffer, String suffix1) throws IOException {
        File temp = File.createTempFile
                ("pattern", suffix1);
        temp.deleteOnExit();
        OutputStream os = new FileOutputStream(temp);
        os.write(buffer, 0, buffer.length);
        os.close();
        return temp;
    }

    public byte[] file2byte(File file) {
        byte[] buffer = null;
        try {
            FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int n;
            while ((n = fis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            buffer = bos.toByteArray();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer;
    }

    public File fromInputStreamToFile(InputStream in, String suffix) throws IOException {
        File temp = null;
        //try {
        temp = File.createTempFile
                ("pattern", suffix);
        temp.deleteOnExit();
        OutputStream os = new FileOutputStream(temp);
        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        os.close();
        in.close();
       *//* } catch (IOException e) {
            logger.info("创建临时文件失败",e);
        }*//*

        return temp;
    }

    public File fromInputStreamToFile(String suffix) throws IOException {

        if (StringUtils.isEmpty(suffix)) {
            throw new RuntimeException("fileName or suffix can not be null");
        }
        File temp = File.createTempFile
                ("pattern", suffix);
        temp.deleteOnExit();
        return temp;
    }*/


}
